<template>
	<view>
		<u-navbar :title="text || title" :leftIconSize="!isShowLeft?0:36" titleStyle="font-size:36rpx" :bgColor="bgColor"
			:titleStyle="{color:'#333'}">
			<template v-if="isShowLeft" slot="left">
				<u-icon v-if="isDetailIcon && !isbackHone" name="../../static/image/navbarLeft.png" color="#333333" size="48" @click="back()"></u-icon>
				<u-icon v-else-if="isDetailIcon && isbackHone" name="arrow-left" color="#333333" size="40" @click="home()" style="margin-left: 18rpx;"></u-icon>
				<u-icon v-else name="arrow-left" :color="is3orf?'#fff':'#333333'" size="40" @click="back()"></u-icon>
			</template>
			<template v-if="isShowRight" slot="right" >
				<slot></slot>
			</template>
		</u-navbar>
	</view>
</template>

<script>
	export default {
		name: "navbar",
		props: {
			text: {
				type: String,
				default: ""
			},
			isShowRight: {
				type: Boolean,
				default: false
			},
			isShowLeft: {
				type: Boolean,
				default: true
			},
			bgColor: {
				type: String,
				default: '#fff'
			},
			isDetailIcon:{
				type: Boolean,
				default: false
			},
			is3orf:{
				type: Boolean,
				default: false
			},
			isbackHone:{
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				title: '微校耗课管理'
			};
		},
		mounted() {
			let pages = getCurrentPages(); //页面示例
			let page = pages[pages.length - 1]; //当前页面实例
			if (page) {
				let currentPageTitle = page.$holder.navigationBarTitleText; //当前页面标题
				this.title = currentPageTitle;
				if (page.route === 'pages/index/index') {
					this.isShowLeft = false
				}
			}
		},
		methods: {
			back() {
				let canNavBack = getCurrentPages();
				if (canNavBack && canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					});
				} else {
					uni.reLaunch({
						url: '/pages/index/index'
					});
				}
			},
			home() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss">
</style>
